package controllers

import (
    "github.com/astaxie/beego"
)

type menu struct {
    Name string
    Url  string
    Open bool
    List []*menu
}

type menuList struct {
    User    *menu
    Station *menu
}

type base struct {
    beego.Controller
    menuList *menuList
}

type alert struct {
    Msg     string
    Type    string
}

func (this *base) Prepare() {
    this.Data["_title"] = ""
    list := new(menuList)
    this.menuList = list
    list.User = &menu{Name: "工作人员管理", Url: "/a/b", List: []*menu{
        &menu{Name:"人员列表", Url:"/Staff/List"},
        &menu{Name:"添加人员", Url:"/Staff/Edit"},
    }}
    list.Station = &menu{Name: "站点管理", Url: "", List: []*menu{
        &menu{Name:"站点列表", Url:"/Station/List"},
    }}

    var ary []*menu
    ary = append(ary, list.Station)
    ary = append(ary, list.User)

    this.Data["_menuList"] = ary
}

func (this *base) SetTitle(tit string) {
    this.Data["_title"] = tit
}

func (this *base) AlertError(msg string) {
    this.Data["_alert"] = alert{msg, "danger"}
}

func (this *base) AlertSuccess(msg string) {
    this.Data["_alert"] = alert{msg, "success"}
}